<?
/**
* Copyright (c) 2002-2007 BioWare Corp.
* http://www.bigdaddymonitor.org
*
* This file is part of the BigDaddy Monitoring
* program. It is free software distributed under
* the terms of the BSD License. It is ditributed
* in the hopes that it will be useful, but
* WITHOUT ANY WARRANTY; without event the implied
* warranty of MERCHANTABILITY or FITNESS FOR A
* PARTICULAR PURPOSE.
*
* The BSD License is available from:
* http://www.opensource.org/licenses/bsd-license.php
**/

function GetAverageByArray($aNum)
{
	if (is_array($aNum))
	{
		foreach ($aNum as $nNum)
		{
			$nTotal += $nNum;
		}
		
		$nAverage = $nTotal / count($aNum);
		
		return $nAverage;
	}
		
}


if (is_array($aModuleInfo))
{
	ob_start();
	$k=1;
	foreach ($aModuleInfo as $aModule)
	{
		if ($aModule["type"] == 1)
		{
			
			if ($k%2 ==0)
			{
				$sStyle = " style=\"background-color:#efefef\"";
			}
			else
			{
				$sStyle = "";
			}
				
			
			$aInfo = $BigDaddyHistory->GetBooleanHistoryByTime($aModule["serverModuleID"], $nStartTime, $sType, $nEndTime, true);
			$nTotal = $aInfo["monitoringend"] - $aInfo["monitoringstart"];
			
			$sParam = str_replace("[hostname]", "", $aModule["parameters"]);
			$sParam = trim($sParam);
			if ($sParam != "")
			{
				$sParam = "(".$sParam.")";
			}
			
			$nPercentUptime = @round( ($aInfo["valuetime"]["1"]/$nTotal*100), 3);
			$nPercentScheduled = @round( ($aInfo["valuetime"]["-1"]/$nTotal*100), 3);
			$nPercentDown = @round( ($aInfo["valuetime"]["0"]/$nTotal*100), 3);
			$nPercentDisabled = @round( ($aInfo["valuetime"]["-2"]/$nTotal*100), 3);
			$nPercentNoData = @round( ($aInfo["valuetime"]["-3"]/$nTotal*100), 3);
			
			$aTotal["1"][] = $nPercentUptime;
			$aTotal["0"][] = $nPercentScheduled;
			$aTotal["-1"][] = $nPercentDown;
			$aTotal["-2"][] = $nPercentDisabled;
			$aTotal["-3"][] = $nPercentNoData;
			
			?>
			<tr>
				<td <?=$sStyle;?>><?=$aModule["hostname"];?> - <?=$aModule["module_name"];?> <?=$sParam;?></td>
				<td <?=$sStyle;?>><?=convertTimeToHours($aInfo["valuetime"]["1"]);?> / <?=$nPercentUptime;?>%</td>
				<td <?=$sStyle;?>><?=convertTimeToHours($aInfo["valuetime"]["0"]);?> / <?=$nPercentDown;?>%</td>
				<td <?=$sStyle;?>><?=convertTimeToHours($aInfo["valuetime"]["-1"]);?> / <?=$nPercentScheduled;?>%</td>
				<td <?=$sStyle;?>><?=convertTimeToHours($aInfo["valuetime"]["-2"]);?> / <?=$nPercentDisabled;?>%</td>
				<td <?=$sStyle;?>><?=convertTimeToHours($aInfo["valuetime"]["-3"]);?> / <?=$nPercentNoData;?>%</td>
			</tr>
			<?
			$k++;
		}
	}
	$sBoolTabular = ob_get_clean();
}

?>

<?
if ($sBoolTabular != "")
{
	?>
		
	<table class="booleandata" cellpadding="3">
	<thead>
		<tr>
		<th>Server/Module</th>
		<th>Uptime</th>
		<th>Downtime</th>
		<th>Scheduled Down</th>
		<th>Disabled</th>
		<th>No Data</th>
		</tr>
	</thead>
	<?
	echo $sBoolTabular;
	?>
	<tfoot>
	<tr>
		<td>Average</td>
		<td><?=@round(GetAverageByArray($aTotal["1"]), 3);?>%</td>
		<td><?=@round(GetAverageByArray($aTotal["-1"]), 3);?>%</td>
		<td><?=@round(GetAverageByArray($aTotal["0"]), 3);?>%</td>
		<td><?=@round(GetAverageByArray($aTotal["-2"]), 3);?>%</td>
		<td><?=@round(GetAverageByArray($aTotal["-3"]), 3);?>%</td>
	</tr>
	</tfoot>
	</table>
	<?
}
?>

	
	
